/**
 * Created by Administrator on 2015/12/3.
 */
Date.prototype.format = function(format){
    var o = {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(), //day
        "h+" : this.getHours(), //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3), //quarter
        "S" : this.getMilliseconds() //millisecond
    }

    if(/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
    }

    for(var k in o) {
        if(new RegExp("("+ k +")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
        }
    }
    return format;
}

//时间戳格式化
function DataForString(val){
    if(!val||val.length==0){
        return "";
    }
    var  date=new Date(val);
    return date.format("yyyy-MM-dd");
}
//时间字符串转时间戳
function DateStringForLong(datastr){
    if(!datastr||datastr.length==0){
        return "";
    }
    var regEx = new RegExp("\\-","gi");
    datastr=datastr.replace(regEx,"/");
    var ticks=Date.parse(datastr);
    return ticks;
}

//性别
function getSexHtml(val) {
    if(val=="1"){
        return "公羊";
    }
    return "母羊"
}
//品种
function getVarHtml(val){
    if(val=="1"){
        return "黑头羊";
    }
    return "哈萨克羊";
}
//生命周期
function getLifeHtml(val){
    switch (val){
        case "1":
            return "未出生";
            break;
        case "2":
            return "小羊";
            break;
        case "3":
            return "成年羊";
            break;
        case "4":
            return "母羊";
            break;
        case "5":
            return "种羊";
            break;
        case "6":
            return "死亡";
            break;
    }
}
//众筹状态
function getCrowdHtml(val){
    switch (val){
        case "1":
            return "未众筹";
            break;
        case "2":
            return "众筹";
            break;
        case "3":
            return "认领";
            break;
        case "4":
            return "认购";
            break;
        case "5":
            return "解除";
            break;
    }
}
//买卖状态
function getSaleHtml(val){
    switch (val){
        case "1":
            return "未众筹";
            break;
        case "2":
            return "拍卖";
            break;
        case "3":
            return "竞拍";
            break;
        case "4":
            return "买卖";
            break;
    }
}

function checkHttp(val){
    var reg=new RegExp("^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$");
    return reg.match(val);
}

